<?
ob_start(); 
include("common/header.html");
$out_html=ob_get_contents();
ob_end_clean();

include('common/autoload.php');
include_once("class/ProOrder.php");
$ac=$GLOBALS['_ac'];
$pw=$GLOBALS['_pw'];

//供应商身份获取他的分销商
if($_SESSION['dtype']==0) {
    $memObject = new \pft\Member\MemberAccount($GLOBALS['le'], $_SESSION['memberID']);
    $myDistors = $memObject->GetRelation($_SESSION['memberID']);
    $DistorsNames = $memObject->getMemName($myDistors);
}

//$s = new SoapClient(null,array("location" => "http://localhost/open/openService/pft_insideMX.php","uri" => "www.16u.com?ac_16u=$ac|pw_16u=$pw|auth_16u=true"));
$s = SoapInit::GetSoapInside();
$memberID=$_SESSION['sid'];
$object = saleProOrderObject($memberID,$s,$_SESSION['sdtype']);
$btime=$_REQUEST['begintime']?$_REQUEST['begintime']:date("Y-m-01");
$etime=$_REQUEST['endtime']?$_REQUEST['endtime']:date("Y-m-d");
$by=$_REQUEST['by']?$_REQUEST['by']:"lid";
$option=array();
if(count($_REQUEST['status'])>0){
	$option['status']=implode("|",$_REQUEST['status']);
}
//交易时间类型
$timeType = isset($_REQUEST['time_type'])? abs($_REQUEST['time_type']) : 1;
//分销商ID
$fid = isset($_REQUEST['fid']) ? abs($_REQUEST['fid']) : 0;
$r=$object->orderSum( $btime." 00:00:00",$etime." 23:59:59",$by,$option,
    $timeType, $fid);
$titleT=array("lid"=>"景区名称","tid"=>"票类名称","mid"=>"分销商名称");
$totals=array();
/*导出EXCEL处理程序--begin-*/
include("ExcelHandle.php");
/*导出EXCEL处理程序--end*/
echo $out_html;
?>
<script src="js/Calendar.js" type="text/javascript"></script>
<script type="text/javascript" src="js/global/Date_func.js"></script>
<link rel="stylesheet" type="text/css" href="css/member.css"/>
<style>
	.report{margin:10px 0; padding:15px; border:1px solid #eee}
	.report span.part{ margin-right:20px;}
	input.time{    background: url("images/rili.png") no-repeat scroll right center #FFFFFF;
    border: 1px solid #7F9DB9;
    height: 20px;
    line-height: 20px;
    width: 120px;}
	.total{ width:100%; text-align:center;}
	input.checkbox{ vertical-align:-2px; margin-right:2px;}
	.btn{ background:#eee; padding:4px 15px; background:url("images/mc_title.png") no-repeat right top; color:#fff; border:none; cursor:pointer}
	#excel{margin-left:10px;}
</style>
	<h3 class="mc_title">
		<span class="mctit_1"><span class="mctit_2">销售报表</span></span>
	</h3>
	<form class="report">
		<input type="hidden" name="act" id="act" value=""/>
		<p>
			<span class="part">
				<label>
<!--                    交易日期：-->
                    <select name="time_type" id="time_type">
                        <option value="1" <?=$_REQUEST['time_type']==1?'selected' :''?>>下单时间</option>
                        <option value="2" <?=$_REQUEST['time_type']==2?'selected' :''?>>使用时间</option>
                        <option value="3" <?=$_REQUEST['time_type']==3?'selected' :''?>>游玩时间</option>
                    </select>
                </label>
				<input type="text" name="begintime" id="begintime" class="time" value="<?=$btime?>" onmouseup="SelectDate(this,'yyyy-MM-dd',0,0)"/>
				<label>至</label>
				<input type="text" name="endtime" id="endtime" class="time" value="<?=$etime?>" onmouseup="SelectDate(this,'yyyy-MM-dd',0,0)"/>
				<select id="time">
					<option value="">选择</option>
					<option value="today" <?=$_REQUEST['timeT']=="today"?"selected":""?>>今天</option>
					<option value="yesterday" <?=$_REQUEST['timeT']=="yesterday"?"selected":""?>>昨天</option>
					<option value="week" <?=$_REQUEST['timeT']=="week"?"selected":""?>>本周</option>
					<option value="lastweek" <?=$_REQUEST['timeT']=="lastweek"?"selected":""?>>上周</option>
					<option value="month" <?=$_REQUEST['timeT']=="month"?"selected":""?>>本月</option>
					<option value="lastmonth" <?=$_REQUEST['timeT']=="lastmonth"?"selected":""?>>上月</option>
				</select>
			</span>
			<span  class="part">
				<input class="checkbox" type="checkbox" name="status[]" <?=in_array("0|6",$_REQUEST['status'])?"checked":""?> value="0|6"/><label>未使用</label>
				<input class="checkbox" type="checkbox" name="status[]" <?=in_array("1",$_REQUEST['status'])?"checked":""?> value="1"/><label>已使用</label>
				<input class="checkbox" type="checkbox" name="status[]" <?=in_array("2",$_REQUEST['status'])?"checked":""?> value="2"/><label>已过期</label>
				<input class="checkbox" type="checkbox" name="status[]" <?=in_array("3|5",$_REQUEST['status'])?"checked":""?> value="3|5"/><label>已取消</label>
			</span>

			<input type="submit" class="btn" value="查 询"/>
			<input type="button" id="excel" class="btn" value="导 出"/>
		</p>
        <?if(isset($DistorsNames) && count($DistorsNames)>0):?>
        <p>
            <span  class="part">
            分销商：<?=GetHtmlSelect($DistorsNames, 'fid', $fid, array('k'=>0,'v'=>'--分销商--'))?>
            </span>
            <span  class="part">
                统计方式：
				<select name="by">
                    <option value="">--选择--</option>
                    <option value="lid" <?=($_REQUEST['by']=="lid")?"selected":""?>>按景区统计</option>
                    <option value="tid" <?=($_REQUEST['by']=="tid")?"selected":""?>>按门票统计</option>
                    <option value="mid" <?=($_REQUEST['by']=="mid")?"selected":""?>>按分销商统计</option>
                </select>
			</span>
        </p>
        <?endif;?>
	</form>
	<div class="rank">
		<div class="rankcon">
			<table class="ranktab">
				<thead id="rankhd">
					<th>序号</th>
					<th class="tL"><?=$titleT[$by]?></th>
					<th><span class="sort" onclick="sortTable('offmain',2, true ,this);">订单数量</span></th>
					<th><span class="sort" onclick="sortTable('offmain',3, true ,this);">门票数量</span></th>
					<th><span class="sort" onclick="sortTable('offmain',4, true ,this);">金额</span></th>
					<th><span class="sort" onclick="sortTable('offmain',5, true ,this);">账户余额</span></th>
					<th><span class="sort" onclick="sortTable('offmain',6, true ,this);">支付宝</span></th>
					<th><span class="sort" onclick="sortTable('offmain',7, true ,this);">供应额度</span></th>
					<th><span class="sort" onclick="sortTable('offmain',8, true ,this);">产品自销</span></th>
				</thead>
				<tbody id="offmain">
					<?foreach($r as $lid=>$row){
						$totals['order']+=$row['order'];
						$totals['tnum']+=$row['tnum'];
						$totals['money']+=$row['money']/100;
						$totals['pmode0']+=$row['pmode0']/100;
						$totals['pmode1']+=$row['pmode1']/100;
						$totals['pmode2']+=$row['pmode2']/100;
						$totals['pmode3']+=$row['pmode3']/100;
					?>
					<tr>
						<td><?=++$n?></td>
						<td class="tL"><?=$row['title']?></td>
						<td><?=$row['order']?></td>
						<td><?=$row['tnum']?></td>
						<td><?=$row['money']/100?></td>
						<td><?=$row['pmode0']/100?></td>
						<td><?=$row['pmode1']/100?></td>
						<td><?=$row['pmode2']/100?></td>
						<td><?=$row['pmode3']/100?></td>
					</tr>
					<?}?>
				</tbody>
				<tfoot>
				<?if(count($r)>0){?>
					<tr>
						<td  colspan="2">总计：</td>
						<td><?=$totals['order']?></td>
						<td><?=$totals['tnum']?></td>
						<td><?=$totals['money']?></td>
						<td><?=$totals['pmode0']?></td>
						<td><?=$totals['pmode1']?></td>
						<td><?=$totals['pmode2']?></td>
						<td><?=$totals['pmode3']?></td>
					</tr>
				<?}else{?>
					<tr>
						<td align="left" colspan="9">&nbsp;&nbsp;&nbsp;交易日期无销售订单！</td>
					</tr>
				<?}?>
				</tfoot>
			</table>
		</div>
	</div>
	<script src="js/jsorder.js"></script>
	<script src="js/jsorder.js"></script>
	<script>
		$("#time").change(function(){
			Date_func.selectDate($(this).val(),$("#begintime").get(0),$("#endtime").get(0));
		});
		$("input.btn").click(function(){
			var btime=$("#begintime").val();
			var etime=$("#endtime").val();
			btime=btime.split("-");
			etime=etime.split("-");
			month=(etime[0]-btime[0])*12+(etime[1]-btime[1]);
			if(month>3){
				alert("交易日期时间间隔不能超过三个月");
				return false;
			}
		});
		$("#excel").click(function(){
			$("#act").val("orderReportExcel");
			$("form.report").submit();
			$("#act").val("");
		});
	</script>
<?
include("common/footer.html");
?>